package cc.mrbird.febs.business.api;

import cc.mrbird.febs.business.domain.Store;
import cc.mrbird.febs.business.service.StoreService;
import cc.mrbird.febs.common.controller.BaseController;
import cc.mrbird.febs.common.domain.QueryRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.Map;

@Slf4j
@Validated
@RestController
@RequestMapping("api/store")
@Api(description = "商家接口")
public class StoreApi extends BaseController {

    @Autowired
    private StoreService storeService;

    @GetMapping("/storeList")
    @ApiOperation(value = "商户列表" ,  notes="商户列表")
    public Map<String, Object> storeList(QueryRequest queryRequest, Store store) {
        return getDataTable(storeService.findStores(store, queryRequest));
    }

    @GetMapping("/storeinfo/{id}")
    @ApiOperation(value = "商户详情" ,  notes="商户详情")
    public Store storeInfo(@NotBlank(message = "{required}") @PathVariable String id) {
        Store result = storeService.getById(id);
        return result;
    }

    @GetMapping("/storeListByCommIdAndStoreType")
    @ApiOperation(value = "指定小区和类型的商户列表" ,  notes="指定小区和类型的商户列表")
    public Map<String, Object> storeListByCommIdAndStoreType(QueryRequest queryRequest, Store store) {
        return getDataTable(storeService.findStores(store, queryRequest));
    }
}
